<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Nonactive extends SMB_Controller {
	
	public function __construct() {
		parent::__construct();
		$this->load->library('scholarship');
	}
	
	public function index() {
		$this->_get_userinfo();
		
		$this->load->helper('ext_form');
		$this->load->helper('table');
		
		$this->_load_common_header();
		$this->_load_common_navigation();
		$this->_load_common_sidebar(get_user_sidebar($this->userinfo['role'], 'scholarship'));
		$params = array(
			'role' => $this->userinfo['role'],
			'sponsors' => $this->scholarship->get_sponsor()
		);
		
		if ($this->input->get('search') == FALSE) {
			$limit = $this->scholarship->count_all_scholarship(NONAKTIF);
			$params['scholarships'] = $this->scholarship->list_offered_scholarship('0', $limit, NONAKTIF);
			$params['title'] = 'Daftar Beasiswa Non-Aktif';
			$params['empty'] = 'Tidak ada beasiswa non-aktif.';
		} else {
			$name = $this->input->get('name', TRUE);
			$sponsor = $this->input->get('sponsor', TRUE);
			if ($name == FALSE) { $name = ''; }
			if ($sponsor == FALSE) { $sponsor = ''; }
			$limit = $this->scholarship->count_all_scholarship(NONAKTIF, $name, $sponsor);
			$params['title'] = 'Daftar Hasil Pencarian Beasiswa';
			$params['empty'] = 'Tidak ada beasiswa non-aktif sesuai dengan kriteria pencarian.';
			$params['scholarships'] = $this->scholarship->list_offered_scholarship('0', $limit, NONAKTIF, $name, $sponsor);
		}
		
		$params['pager'] = get_pager(6);
		$this->load->view('common/scholar_nonactive_list', $params); 
		$this->_load_common_footer();
	}
	
	public function detail($id = NULL) {
		$this->_get_userinfo();
		if ($id == NULL) {
			redirect($this->userinfo['role'].'/scholar/nonactive/index', 'location');
			exit;
		}
		$scholarship = $this->scholarship->get_scholarship_by_id_and_status($id, NONAKTIF);
		if ($scholarship == NULL) {
			redirect($this->userinfo['role'].'/scholar/nonactive/index', 'location');
			exit;
		}
		
		$this->load->helper('table');
		$limit = $this->scholarship->count_reciever_scholarship($scholarship->id, NONAKTIF);
		
		$this->_load_common_header();
		$this->_load_common_navigation();
		$this->_load_common_sidebar(get_user_sidebar($this->userinfo['role'], 'scholarship'));
		$params = array(
			'role' => $this->userinfo['role'],
			'scholarship' => $scholarship,
			'type' => NONAKTIF,
			'status' => 'non-aktif',
			'title' => 'Daftar Mahasiswa Penerima Beasiswa',
			'empty' => 'Tidak ada mahasiswa menerima beasiswa ini.',
			'studentstatus' => 'Status Pengiriman',
			'countertitle' => 'Jumlah Penerima',
			'counter' => $limit,
			'recievers' => $this->scholarship->get_reciever_scholarship($id, '0', $limit, NONAKTIF),
			'pager' => get_pager(4)
		);
		$this->load->view('common/scholar_nonactive_detail', $params);
		$this->_load_common_footer();
	}
}